-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add any()
and all()
methods to Array
#50349
Conversation
569ecc3
to
5d412a6
Compare
I have no strong preference, but I like how |
Ruby and Python also use |
I also agree that any/all is more to my taste as I'm used to those ones in Kotlin collections. |
As GdScript is a Python like syntax language, it's better to match when it's possible the Python syntax, especially for little thing like this. |
@fabriceci It's not, it's just another indentation based language. Though in this case it wouldn't matter as there are several other popular languages that use the same method names. |
@pycbouh Well yes, GDScript is a Python-like language. We've often erred on the side of using the same names and syntaxes as Python whenever it was left to preference, unless the Python ones were really weird. GDScript is heavily inspired from the Godot API in C++, and sprinkled with bits of JavaScript and Rust. Anyway, if it's "the whole world" vs "JavaScript", I suggest we follow "the whole world" here. |
Yes, I guess sorry to fabriceci, I always read too strongly into people comparing the two. |
The Python I personally think List comprehension is clearer in this case but GDScript doesn't have it. I don't know about the other languages but GDScript is Python-like and so I think the proposed names In either case, if these functions are implemented they should be callable without passing a function, in which case the function essentially defaults to just bool evaluation. |
5dc1592
to
063a5c2
Compare
some()
and every()
methods to Arrayany()
and all()
methods to Array
I renamed |
9f405c3
to
c9c3594
Compare
Late to the discussion, but |
These can be used as faster, more convenient shorthands to using `filter()` + `size()`.
c9c3594
to
a98e31a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved in PR review meeting.
Thanks! |
wouldn't it be clearer to use should we be consistent in that methods that return bool, start with |
I do agree with that, but in this case it's either breaking a convention or being consistent with the So I would actually prefer if they stayed this way. |
|
These can be used as faster, more convenient shorthands to using
filter()
+size()
.This closes godotengine/godot-proposals#2926.
reduce_right()
wasn't implemented as it wasn't deemed useful enough in daily use cases.Testing code